/**   
 * @Title: TypeServiceImple.java
 * @Package com.cityoneyes.service.impl
 * @Description: TODO
 * @author Rick
 * @date 2011-8-4 下午10:24:46
 * @version V1.0   
 */
package com.cityoneyes.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.cityoneyes.bean.Type;
import com.cityoneyes.dao.ITypeDAO;
import com.cityoneyes.service.ITypeService;

/**
 * @ClassName: TypeServiceImple
 * @Description: 通用类型service实现类
 * @author Rick
 * @date 2011-8-4 下午10:24:46
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class })
public class TypeServiceImple extends BaseServiceImpl implements ITypeService {
	
	// 缓存数据
	private static Map<String, Type> map = null;
	
	@Autowired
	private ITypeDAO typeDao;

	@Override
	public Map<String, Type> init() {
		if (map == null) {
			List<Type> list = typeDao.getParentTypes();
			if (list != null && list.size() > 0) {
				for (Type obj : list) {
					if (obj != null && obj.getCode() != null && obj.getCode().length() > 0) {
						if (!map.containsKey(obj.getCode())) {
							map.put(obj.getCode(), obj);
						}
					}
				}
				return map;
			}
		}
		return null;
	}
	
}
